package com.clk.portfoy.complib.portfoy.degerlendirme;

import java.util.Vector;

import javax.swing.table.DefaultTableModel;

import com.clk.desktop.gui.components.advance.table.ClkTable;
import com.clk.portfoy.classlib.portfoy.AbsDeger;
import com.clk.portfoy.classlib.portfoy.Portfoy;
import com.clk.portfoy.complib.NumberCellRenderer;
import com.clk.portfoy.complib.PortfoyDegerCellRenderer;
import com.clk.portfoy.complib.PortfoyKZCellRenderer;
import com.clk.portfoy.complib.TextCellRenderer;
import com.clk.portfoy.complib.portfoy.degerlendirme.ClkDegerlendirmeRow.DEGERLENDIRME_COLUMN;

public class ClkDegerlendirmeTable extends ClkTable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// ---------------------------------------------------------------------------------
	@SuppressWarnings("rawtypes")
	public ClkDegerlendirmeTable() {
		this(new Vector<Vector>(), ClkDegerlendirmeRow.getColumnData());
		ClkDegerlendirmeRow.prepareDegerlendirmeTableColumnSize(this);
	}

	// ---------------------------------------------------------------------------------
	@SuppressWarnings("rawtypes")
	public ClkDegerlendirmeTable(Vector<Vector> rowData, Vector<String> columnNames) {
		super(rowData, columnNames);
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.ISIM.getIndex()).setCellRenderer(new TextCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.GRUP.getIndex()).setCellRenderer(new TextCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.ADET.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.ANLIK_LOT.getIndex()).setCellRenderer(new PortfoyDegerCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.SATIS_LOT.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.PER_SEANS_FARK.getIndex()).setCellRenderer(new PortfoyKZCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.ANLIK_TOT.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.MALIYET_LOT.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.POT_KZ.getIndex()).setCellRenderer(new PortfoyKZCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.PER_KZ.getIndex()).setCellRenderer(new PortfoyKZCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.PORTFOY_DAGILIM.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.HEDEF_SATIS_LOT.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.HEDEF_SATIS_TOT.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.HEDEF_POTKZ.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.HEDEF_PERKZ.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.ALIS_TARIHI.getIndex()).setCellRenderer(new TextCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.VADE.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.FAIZ.getIndex()).setCellRenderer(new NumberCellRenderer());
		this.getColumnModel().getColumn(DEGERLENDIRME_COLUMN.DEGERLENDIRME.getIndex()).setCellRenderer(new PortfoyKZCellRenderer());
	}

	// ---------------------------------------------------------------------------------
	public void setPortfoy(Portfoy p) {
		clearTable();
		for (AbsDeger deger : p.getDegerler()) {
			addRow(deger);
		}
	}

	// ---------------------------------------------------------------------------------
	private void addRow(AbsDeger deger) {
		DefaultTableModel model = (DefaultTableModel) this.getModel();
		model.addRow(ClkDegerlendirmeRow.rowConverter(deger));
	}

	// ---------------------------------------------------------------------------------
	public void clearTable() {
		DefaultTableModel dm = (DefaultTableModel) getModel();
		dm.getDataVector().removeAllElements();
		revalidate();
	}
	// ---------------------------------------------------------------------------------
}
